package cn.ncu.wechat.controller;

import cn.ncu.wechat.service.ProductService;
import cn.ncu.wechat.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/api/wx/products")
    public Result<?> getProductList(@RequestParam Integer page,@RequestParam Integer pageSize){
        if(page<=0||page==null||pageSize<=0||pageSize==null){
            return Result.fail(400,"请求参数错误");
        }
        return productService.getProductList(page,pageSize);
    }

    @GetMapping("/api/wx/products/{id}")
    public Result<?> getProductDetail(@PathVariable Long id){
        return productService.getProductDetail(id);
    }

}
